package com.apexedu.portal.service.impl;

import com.apexedu.biz.Const;
import com.apexedu.biz.entity.TServiceSatisfaction;
import com.apexedu.framework.service.impl.AbstractBaseServiceSupport;
import com.apexedu.framework.util.DBUtil;
import com.apexedu.framework.util.Pager;
import com.apexedu.identity.action.IdLoginAction;
import com.apexedu.portal.action.PortalEvaluationAction;
import com.apexedu.sys.util.BusinessLogUtil;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 评论信息管理
 */

@Service("portalEvaluationService")
public class PortalEvaluationServiceImpl extends AbstractBaseServiceSupport {

    private static final Logger logger = Logger.getLogger(PortalEvaluationServiceImpl.class);

    public List<?> list(Object myaction, Pager pager) throws Exception {
        PortalEvaluationAction action = (PortalEvaluationAction) myaction;
        long c=DBUtil.count("select count(*) as c from T_Service_Satisfaction t ");
        pager.setTotalRows(c);
        String sql =" select t.wid,t.nr,(select menuname from t_sys_menu where menuid=t.menuid) as menuid,t.satisfaction,(select username from t_sys_user where userloginid=t.cjr) as cjr，cjrq " +
                    " from T_Service_Satisfaction t order by t.cjrq desc ,t.menuid";
        List<TServiceSatisfaction> list = DBUtil.queryPageBeanList(pager,sql, TServiceSatisfaction.class);
        return list;
    }

    @Override
    public void saveOrUpdate(Object myaction) throws Exception {

    }

    @Override
    public void load(Object myaction) throws Exception {
        PortalEvaluationAction action = (PortalEvaluationAction) myaction;
        String wid = action.getWid();
        String sql=" select t.wid,t.nr,(select menuname from t_sys_menu where menuid=t.menuid) as menuid,t.satisfaction,(select username from t_sys_user where userloginid=t.cjr) as cjr，t.cjrq " +
                   " from T_Service_Satisfaction t " +
                   " where t.wid = ?";
        TServiceSatisfaction tserviceSatisfaction = DBUtil.queryBean(sql, TServiceSatisfaction.class, wid);
        action.setTserviceSatisfaction(tserviceSatisfaction);
    }

    @Override
    public boolean remove(Object myaction) throws Exception {
        PortalEvaluationAction action = (PortalEvaluationAction) myaction;
        String ids = action.getWid();
        boolean deleteSuccess = getBaseDao().deleteAll("TServiceSatisfaction", "wid", "=", ids);
        BusinessLogUtil.log(action.getUserloginid(), Const.CZDX_T_SERVICE_SATISFACTION, Const.LOG_ACTION_DEL, IdLoginAction.getIpAddr(action.getRequest()));
        return deleteSuccess;
    }
}
